/*
 * Endless Code License
 * Copyright (C) 2009 Jingul, Kim
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "ecFont.h"

FT_Library library;

JNIEXPORT jboolean JNICALL Java_ec_gfx_font_FreeType_start(JNIEnv *env, jobject obj) {

	if (FT_Init_FreeType(&library)) {
		return JNI_FALSE;
	}

	return JNI_TRUE;
}

JNIEXPORT jboolean JNICALL Java_ec_gfx_font_FreeType_done(JNIEnv *env, jobject obj) {

	if (FT_Done_FreeType(library)) {
		return JNI_FALSE;
	}

	return JNI_TRUE;
}

JNIEXPORT jint JNICALL Java_ec_gfx_font_Font_create(JNIEnv *env, jobject obj,
		jstring arg_path) {
	FT_Face face;

	const char *path = env->GetStringUTFChars(arg_path, JNI_FALSE);

	FT_Error error;

	error = FT_New_Face(library, (char*) path, 0, &face);
	env->ReleaseStringUTFChars(arg_path, path);

	if (error == FT_Err_Unknown_File_Format) {
		puts("error format");
		return 0;
	} else if (error) {
		puts("error etc");
	}

	return (jint) face;
}

JNIEXPORT void JNICALL Java_ec_gfx_font_Font_dispose(JNIEnv *env, jobject obj,
		jint ft_face) {
	FT_Done_Face((FT_Face) ft_face);
}

JNIEXPORT void JNICALL Java_ec_gfx_font_Font_setSize(JNIEnv *, jobject, jint aFace, jint size)
{
	FT_Face face = (FT_Face)aFace;
	FT_Set_Char_Size(face, size << 6, 0, 300, 300);
}

JNIEXPORT void JNICALL Java_ec_gfx_font_Font_bolden(JNIEnv *, jobject, jint aFace)
{
	FT_Face face = (FT_Face)aFace;

}
